﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using Business.Models;
using System.Data;

namespace Business.DAO
{
    public class AdministratorsDAO
    {  
        private ISSContext db = new ISSContext();
        public List<Administrators> GetAll() 
        {
            return db.administrators.ToList();
        }

        public Administrators Get(int id)
        {
            Administrators administrators = db.administrators.Find(id);
            return administrators;
        }

        public int Create(Administrators administrator)
        {
            try
            {
                db.administrators.Add(administrator);
                return db.SaveChanges();
            }
            catch (Exception ex)
            {
                return 0;
            }
        }

        public int Edit(Administrators administrator)
        {
            try
            {
                db.Entry(administrator).State = EntityState.Modified;
                return db.SaveChanges();
            }
            catch(Exception ex)
            {
                return 0;
            }  
        }

        public int Delete(int id)
        {
            try
            {
                Administrators administrators = db.administrators.Find(id);
                db.administrators.Remove(administrators);
                return db.SaveChanges();
            }
            catch (Exception ex)
            {
                return 0;
            }
        }

        public Administrators Login(String Name, String Password)
        {
            try
            {
                Administrators a = db.administrators.Where(m => m.TenAdministrator == Name && m.MatKhau == Password).First();
                return a;
            }
            catch (Exception ex)
            {
                return null;
            }
        }
        
    }
}